<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="referrer" content="no-referrer" />
    <title>评论页面</title>
    <script src="js/jquery-1.11.0.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <style>
        .left-side {
            position: fixed;
            top: 0;
            bottom: 0;
            z-index: 5;
            display: block;
            width: 240px;
            font-weight: 500;
        }

        ul {
            list-style: none;
        }
    </style>
    <script>
        $(function () {
            console.log("进入头部");
            $(".header").load("headHtml");
            $.ajax({
                url: "/getComments",
                type: "POST",
                success: function (result) {
                    console.log("---------");
                    console.log(result);
                    console.log("---------");
                    if (result != null) {
                        $imgs = $(".comments");
                        var li = '';
                        for (let i = 0; i < result.length; i++) {
                            li = li + '<a href="#" onclick="huifuchuxian(' + result[i].id + ')"><div id="contentCon" style="margin: 0 auto;height: fit-content">\n' +
                                '                                <p id="title" style="font-size: 30px">>> ' + result[i].user + '</p>\n' +
                                '                                <p id="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].com + '<button onclick="jubao(' + result[i].id + ')">举报</button></p>\n' +
                                '                                <p id="date" style="float: right">' + rTime(result[i].date) + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></br>\n' +
                                '                            </div></a></br>' +
                                '                                <div id="response' + result[i].id + '" style="display: none;">' +
                                '<div class="comment-form"><textarea class="commentres' + result[i].id + '" style="width: 100%;margin: 0 auto;height: fit-content;"></textarea><button onclick="response(' + result[i].id + ')">回复</button></div></div>\n\n' +
                                '<a id="xianshi" onclick="gengduo(' + result[i].id + ')" href="#">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;更多</a><a id="xianshi" onclick="shouqi(' + result[i].id + ')" href="#">&nbsp;&nbsp;收起</a><div id="responses' + result[i].id + '" style="background-color: #d2ffac;width: 80%;"></div>';
                        }
                        $imgs.html(li);
                    }
                }
            });

        });
        function gengduo(a){
            $.ajax({
                url: "/getResponses",
                type: "POST",
                data: JSON.stringify({"id": a}),
                contentType: "application/json",
                dataType: "json",
                success: function (result) {
                    console.log("---------");
                    console.log(result);
                    console.log("---------");
                    if (result != null) {
                        $imgs = $("#responses" + a);
                        var li = '';
                        for (let i = 0; i < result.length; i++) {
                            li = li + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].user + '回复' + result[i].lastuser + ':' + result[i].com + rTime(result[i].date) + '<button onclick="jubao(' + result[i].id + ')">举报</button></br>';
                        }
                        $imgs.html(li);
                    }
                }
            });
        }
        function jubao(a){
            $.post("/getUserName", function (obj) {
                if (obj!=null&&obj!=100) {
                    $.ajax({
                        url: "/jubao",
                        type: "POST",
                        data: JSON.stringify({"id": a}),
                        contentType: "application/json",
                        dataType: "json",
                        success: function (result) {
                            if (result===1){
                                console.log(result);
                                confirm("举报成功！");
                            }
                        }
                    });
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "comment";
                    }
                }
            }, "json");
        }
        function shouqi(a){
            $.ajax({
                url: "/getResponses",
                type: "POST",
                data: JSON.stringify({"id": a}),
                contentType: "application/json",
                dataType: "json",
                success: function (result) {
                    console.log("---------");
                    console.log(result);
                    console.log("---------");
                    if (result != null) {
                        $imgs = $("#responses" + a);
                        var li = '';
                        $imgs.html(li);
                    }
                }
            });
        }
        function comment(){
            var comment = $(".comment").val();
            console.log("输入框内容为：" + comment);
            $.post("/getUserName", function (obj) {
                if (obj!=null&&obj!=100) {
                    $.ajax({
                        url: "/addComment",
                        type: "POST",
                        data: JSON.stringify({"comment": comment}),
                        contentType: "application/json",
                        dataType: "json",
                        success: function (result) {
                            console.log("---------");
                            console.log(result);
                            console.log("---------");
                            if (result===1){
                                confirm("评论成功！");
                                window.location.href = "comment";
                            }else {
                                confirm("您没有权限评论！请等管理员开启权限！");
                            }
                        }
                    })
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "comment";
                    }
                }
            }, "json");
        }
        function response(a){
            var comment = $(".commentres" + a).val();
            console.log("输入框内容为：" + comment);
            $.post("/getUserName", function (obj) {
                if (obj!=null&&obj!=100) {
                    $.ajax({
                        url: "/addResopnse",
                        type: "POST",
                        data: JSON.stringify({"comment": comment,"id":a}),
                        contentType: "application/json",
                        dataType: "json",
                        success: function (result) {
                            console.log("---------");
                            console.log(result);
                            console.log("---------");
                            if (result===1){
                                confirm("评论成功！");
                                window.location.href = "comment";
                            }else {
                                confirm("您没有权限评论！请等管理员开启权限！")
                            }
                        }
                    })
                } else {
                    if (confirm("您还未登录，是否先登录？")) {
                        console.log("您选择了是");
                        window.location.href = "loginHtml";
                    } else {
                        console.log("您选择了否");
                        window.location.href = "comment";
                    }
                }
            }, "json");
        }
        function rTime(date) {
            var json_date = new Date(date).toJSON();
            return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        }
        function huifuchuxian(a){
            if (document.getElementById("response" + a).style.display==='none'){
                document.getElementById("response" + a).style.display = 'block';
            }else {
                document.getElementById("response" + a).style.display = 'none';
            }
        }
    </script>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <h1 style="text-align: center;color: #33cabb;">Spider</h1>
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <nav class="sidebar-main">
                    <ul class="nav nav-drawer" style="list-style: none">
                        <li class="nav-item active"><a href="/notice"><i class="mdi mdi-home"></i>公告栏</a></li>
                        <li class="nav-item active"><a href="/index"><i class="mdi mdi-home"></i>爬取图片</a></li>
                        <li class="nav-item active"><a href="/displayHtml"><i class="mdi mdi-home"></i>我的收藏</a></li>
                        <li class="nav-item active"><a href="/share"><i class="mdi mdi-home"></i>好图分享</a></li>
                        <li class="nav-item active submenu"><a href="#"><i class="mdi mdi-home"></i>个人中心</a>
                            <ul class="nav nav-drawer">
                                <li class="nav-item active"><a href="/self">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>信息编辑</a></li>
                                <li class="nav-item active"><a href="/record">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>爬取记录</a></li>
                                <li class="nav-item active"><a href="/comment">&nbsp&nbsp&nbsp&nbsp<i class="mdi mdi-step-forward"></i>评论反馈</a></li>
                            </ul>
                        </li>
                    </ul>
                </nav>
            </div>
        </aside>
        <!--End 左侧导航-->
        <!--头部信息-->
        <div class="header"></div>
        <!--End 头部信息-->
        <!-- 主题内容 -->
        <!--页面主要内容 table table-striped table-hover-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="comment-form">
                                <textarea class="comment" style="width: 100%"></textarea>
                                <div class="items">
                                    <button onclick="comment()">评论</button>
                                </div>
                            </div>
                            <div class="comments"></div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</body>
</html>